using System;
using System.Collections;
using System.Xml;

namespace Slaks.DocumentSerialization
{
	/*
	 *  <term_id_info>
	 *    <entry term="slaks" id=2/>
	 *    <entry term="kuki" id=3/>
	 *  </term_id_info>
	 */
	public class TermIdInfo
	{
		private IDictionary m_termIdDictionary;
		public TermIdInfo()
		{
		}

		public IDictionary TermIdDictionary
		{
			get { return m_termIdDictionary; }
			set { m_termIdDictionary = value; }
		}

		public void XmlWrite(string path)
		{
			XmlTextWriter writer = null;
			
			try
			{
				writer = new XmlTextWriter(path,System.Text.Encoding.UTF8);
				writer.Formatting = System.Xml.Formatting.Indented;
				writer.WriteStartDocument();
				
				writer.WriteStartElement(Grammar.TermIdInfo.TermIdInfoElement);
				long id;
				foreach(string term in m_termIdDictionary.Keys)
				{
					id = (long)m_termIdDictionary[term];
					writer.WriteStartElement(Grammar.TermIdInfo.EntryElement);
           writer.WriteStartAttribute(Grammar.TermIdInfo.TermAttr,"");
					  writer.WriteString(term);
					 writer.WriteEndAttribute();
					 writer.WriteStartAttribute(Grammar.TermIdInfo.IdAttr,"");
					  writer.WriteString(id.ToString());
					 writer.WriteEndAttribute();
					writer.WriteEndElement();
				}
				writer.WriteEndElement();
				writer.WriteEndDocument();
			}
			catch(Exception ex)
			{
				throw ex;
			}
			finally
			{
				writer.Close();
			}
		}
	}
}
